package com.sds.sweng.swat.miplatform.ui.design.models.area.sub;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.PropertyDescriptor;

import com.sds.sweng.swat.miplatform.ui.design.models.component.MColumn;
import com.sds.sweng.swat.miplatform.ui.design.models.component.MGrid;
import com.sds.sweng.swat.miplatform.ui.design.models.component.MGridBody;
import com.sds.sweng.swat.miplatform.ui.design.models.component.MGridHead;

public class GridSubArea extends SubArea {

	public static final int MINIMUM_WIDTH = 100;
	public static final int MODEL_HEIGHT = 122;

	public static final String
		GRID = "grid";

	static {
		descriptors = new IPropertyDescriptor[] {
			new PropertyDescriptor(GRID, "Grid")
		};
	}

	private MGrid grid;

	public GridSubArea() {
		List<MColumn> columns = new ArrayList<MColumn>();
		List<MGridHead> gridHeads = new ArrayList<MGridHead>();
		List<MGridBody> gridBodys = new ArrayList<MGridBody>();

		grid = new MGrid();
		grid.setColumns(columns);
		grid.setGridHeads(gridHeads);
		grid.setGridBodys(gridBodys);
	}

	public GridSubArea clone() {
		GridSubArea clone = (GridSubArea) super.clone();
		clone.setGrid(getGrid().clone());

		return clone;
	}

	public MGrid getGrid() {
		return grid;
	}

	public void setGrid(MGrid grid) {
		this.grid = grid;
		firePropertyChange(GRID, null, grid);
	}

	public Object getPropertyValue(Object id) {
		if (GRID.equals(id))
			return getGrid();

		return null;
	}

	public void setPropertyValue(Object id, Object value) {
		if (GRID.equals(id))
			setGrid((MGrid) value);
	}

	@Override
	public boolean isEmpty() {
		if (grid.getGridHeads().size() > 0)
			return false;

		return true;
	}

	@Override
	public int getRemainWidth() {
		return getWidth() - MINIMUM_WIDTH;
	}

	@Override
	public int getRequireWidth() {
		return MINIMUM_WIDTH;
	}

}
